#include "common.h"

void establishAccount()
{	
	//1. send message
	struct Msg m1;
	//struct Msg msg = {M_OPEN,acc};
	//name
        printf( "name : " );
        fgets(m1.acc.name, sizeof(m1.acc.name), stdin);
        if (strlen(m1.acc.name) == sizeof (m1.acc.name) - 1 && m1.acc.name[sizeof(m1.acc.name) - 2] != '\n')
        {
		scanf( "%*[^\n]");
                scanf( "%*c");
        }
	//password
	char pwd1[20] = {};
	char pwd2[20] = {};
	while(!strcmp(pwd1,pwd2))
	{
		printf( "password : " );
	        scanf( "%s", pwd1);
        	scanf( "%*[^\n]");
	        scanf( "%*c");
		printf( "password again : " );
	        scanf( "%s", pwd2);
        	scanf( "%*[^\n]");
	        scanf( "%*c");		
	}
	strcpy(m1.acc.pwd,pwd1);
	
	//balance	
	printf( "balance : " );
	scanf( "%f", &m1.acc.balance);
        scanf( "%*[^\n]");
	scanf( "%*c");
	
	//send messages to server
	key_t key = ftok(".",200);
	int msgid = msgget(key,IPC_CREAT|0660);
	if(msgid == -1)
		perror("msgget") , exit(-1);
	m1.mtype = 1;
	msgsnd(msgid , &m1 , sizeof(m1) , 0);
	printf("send application successfully!");
	
	//recevie messages from server
}
